package chapter6;

public class Cow {
    private double weight;
    public Cow() {}
    public Cow(double weight) {
        this.weight = weight;
    }

    /**
     * 私有非静态内部类
     */
    private class CowLeg {
        /*
            内部类的私有字段，外部类无法访问
         */
        private double length;
        private String color;
        public CowLeg() {}
        public CowLeg(double length, String color) {
            this.length = length;
            this.color = color;
        }

        public double getLength() {
            return length;
        }

        public void setLength(double length) {
            this.length = length;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }
        //内部类的实例方法，外部类可以访问
        public void info() {
            System.out.println("当前牛腿颜色是:" + color + " 高:" + length);
            //内部类访问外部类的私有变量
            System.out.println("奶牛重:" + weight);
        }
    }

    public void test() {
        CowLeg cl = new CowLeg(1.12, "黑白相间");
        cl.info();
    }

    public static void main(String[] args) {
        Cow cow = new Cow(378.9);
        cow.test();
    }
}
